home *** CD-ROM | disk | FTP | other *** search
- Path: news.inet.fi!usenet
- From: Risto Jokinen <hatrjo@hat-fi.kone.com>
- Newsgroups: comp.arch.embedded,comp.lang.c
- Subject: Re: Using malloc of C on embedded system?
- Date: 2 Apr 1996 17:16:42 GMT
- Organization: Telecom Finland News Service
- Message-ID: <4jrndq$ate@kuikka.inet.fi>
- References: <4jml7h$cbc@castor.usc.edu>
- NNTP-Posting-Host: 138.249.2.139
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
- you can use malloc and even free in embedded systems, but if you like to use free,
- you should change malloc/free functions to have clear book-keeping which is needed
- during the software testing/runtime error recovery(watchdog!)
-
- some simple instructions if you like to use malloc and free
-
- - malloc memory in fixed size blocks (like buffer pool)
- - before first malloc, initialice whole free memory to the fixed blocks (partitions)
- and have link fields between them.
- [block1]-->[block2]->[block3] etc... set 'free' pointer to the block1
-
- - during the malloc, reserve block1 by assigning free pointer to the next pointer
- which was found from the beginning of block1 and at a same time write some debugging
- who-why-when information to the end of block1
- - when you run free, join this block to the chain by changing 'free' pointer to
- point this block and this block is then wired to the previous free block. add more
- who-why-when information to this block.
-
- - run system for a while (minute, day, week), and look over all blocks (using some
- tool) and check if there is lost blocks, or some strange who-what-when syndromes
- etc.
-
- This mechanism works. random size malloc/free does not work on embedded systems, or
- at least it is impossible to debug, and can be VERY slow. fixed size partition pool
- manager takes <<50us for malloc/free in any processor.
-
- -- Risto Jokinen
-
-
-